home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / string.stl < prev    next >
Encoding:
Text File  |  1998-02-09  |  58.9 KB  |  1,728 lines

  1. #ifndef __STD_STRING
  2. #define __STD_STRING
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * string - Declarations for the Standard Library string classes
  8.  *
  9.  * $Id: string,v 1.208 1996/11/05 18:54:08 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  *
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44.  
  45. #include <stdcomp.h>
  46. #include "rw/stddefs.h"
  47.  
  48.  
  49. #ifndef _RWSTD_NO_NEW_HEADER
  50. #include <cstring>
  51. #include <cctype>
  52. #else
  53. #include <string.h>
  54. #include <ctype.h>
  55. #endif
  56.  
  57. #ifndef _RWSTD_HEADER_REQUIRES_HPP
  58. #include <memory>     // For allocator.
  59. #else
  60. #include <memory.hpp>     // For allocator.
  61. #endif
  62.  
  63. #ifdef _RWSTD_MULTI_THREAD
  64. #include "rw/stdmutex.h"
  65. #endif
  66.  
  67. #ifndef _RWSTD_NO_WIDE_CHAR
  68. #ifndef _RWSTD_NO_NEW_HEADER
  69. #include <cwchar>
  70. #include <cwctype>
  71. #else
  72. #ifndef _RWSTD_NO_WCHAR_H
  73. #include <wchar.h>
  74. #endif
  75. #ifndef _RWSTD_NO_WCTYPE_H
  76. # include <wctype.h>
  77. #endif
  78. #endif
  79. #endif
  80.  
  81. #ifndef _RW_STD_IOSTREAM
  82. #include <iostream.h>
  83. #endif
  84.  
  85. //
  86. // Turn off the warnings under the MSVC compiler that
  87. // say 'bool reserved for future use'
  88. //
  89. #ifdef _RWSTD_MSVC_BOOL_WARNING
  90. #pragma warning ( disable : 4237 )
  91. #endif
  92.  
  93. //
  94. // Helper macros used by containers to get around lack of 
  95. // complex template parameter defaults 
  96. //
  97. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  98. #define _RWSTD_TDFLT(d) = d /* */
  99. #else
  100. #define _RWSTD_TDFLT(d) /* */
  101. #endif
  102.  
  103. #if defined(_RWSTD_MULTI_THREAD) && !defined(_RWSTD_NO_TEST_AND_SET)
  104. #ifdef __WIN32__
  105. #define _RWSTD_MT_INCREMENT(v) InterlockedIncrement(&v)
  106. #define _RWSTD_MT_DECREMENT(v) InterlockedDecrement(&v)
  107. #define _RWSTD_MT_SET(v,new) InterlockedExchange(&v,new)
  108. #else
  109. #define _RWSTD_MT_INCREMENT(v) v++
  110. #define _RWSTD_MT_DECREMENT(v) v--
  111. #define _RWSTD_MT_SET(v,new) v = new
  112. #endif // __WIN32__
  113. #else
  114. #define _RWSTD_MT_INCREMENT(v) v++
  115. #define _RWSTD_MT_DECREMENT(v) v--
  116. #define _RWSTD_MT_SET(v,new) v = new
  117. #endif // _RWSTD_MULTI_THREAD
  118.  
  119. #include <rw/traits>
  120.  
  121. #ifndef _RWSTD_NO_NAMESPACE
  122. namespace __rwstd {
  123. #endif
  124.  
  125. //
  126. // Global error message declarations
  127. //
  128. extern const char _RWSTDExportFunc(*) rwse_InvalidSizeParam;
  129. extern const char _RWSTDExportFunc(*) rwse_PosBeyondEndOfString;
  130. extern const char _RWSTDExportFunc(*) rwse_ResultLenInvalid;
  131. extern const char _RWSTDExportFunc(*) rwse_StringIndexOutOfRange;
  132. extern const char _RWSTDExportFunc(*) rwse_UnexpectedNullPtr;
  133.  
  134. // Class & Structure Declarations
  135. template< class charT, class traits, class Allocator > class string_ref;
  136.  
  137. #ifndef _RWSTD_NO_NAMESPACE
  138. }
  139. namespace std {
  140. #endif
  141.  
  142. //
  143. // Class & Structure Declarations
  144. //
  145.  
  146. template<class charT>  struct _RWSTDExportTemplate char_traits;
  147.  
  148. template< class charT, class traits _RWSTD_TDFLT(char_traits<charT>)
  149.  , class Allocator _RWSTD_TDFLT(allocator<charT>) >
  150. class basic_string;
  151.  
  152. #ifndef _RWSTD_NO_NAMESPACE
  153. }
  154. namespace __rwstd {
  155. #endif
  156.  
  157. template <class Allocator>
  158. class _RWSTDExportTemplate string_ref_rep
  159. {
  160.  public:
  161.   //  the refs_ are initialized to 1 because of a problem
  162.   //  where the destructor was being called when it
  163.   //  should not be.
  164.   
  165.   string_ref_rep() : refs_(0), capacity_(0), nchars_(0), can_ref_(true)  {;}
  166.   string_ref_rep(unsigned long x) : refs_(x), capacity_(0),
  167.                                     nchars_(0), can_ref_(true)  {;}
  168.   
  169.   typedef Allocator                        allocator_type;
  170.   typedef _TYPENAME _RWSTD_ALLOC_SIZE_TYPE   size_type;
  171.  
  172.  protected:
  173.   
  174. #ifdef _RWSTD_MULTI_THREAD && defined(_RWSTD_NO_TEST_AND_SET)
  175.   _RWSTDMutex mutex_;
  176. #endif
  177.  
  178.   long   refs_;               // (1 less than) number of references
  179.  
  180.   size_type       capacity_;  // Size of allocated memory
  181.   size_type       nchars_;    // Number of actual data values stored
  182. #ifndef _RWSTD_NO_TEST_AND_SET
  183.   long            can_ref_;    // true if reference counting enabled
  184. #else
  185.   bool            can_ref_;    // true if reference counting enabled
  186. #endif // _RWSTD_NO_TEST_AND_SET
  187.  
  188. };
  189.  
  190.  
  191. template <class charT, class traits , class Allocator >
  192. struct _RWSTDExportTemplate null_string_ref_rep
  193. {
  194.   //
  195.   // ref_hdr has to be immediately followed by eos_char !
  196.   //
  197.   string_ref_rep<Allocator>      ref_hdr;
  198.   charT                          eos_char; 
  199.  
  200.   null_string_ref_rep () : ref_hdr(1), eos_char(charT(0)) {;}
  201.   null_string_ref_rep (const null_string_ref_rep<charT,traits,Allocator>&)
  202.     : eos_char(charT(0)) {;}
  203.  
  204. };
  205.  
  206.  
  207. #ifdef _RWSTD_NO_STATIC_DEF3
  208. extern unsigned long _RWSTDExport nullref[];
  209. extern bool _RWSTDExport nullref_initialized;
  210. #endif
  211.  
  212.  
  213. template <class charT, class traits , class Allocator >
  214. class _RWSTDExportTemplate string_ref : public string_ref_rep<Allocator>
  215. {
  216.   typedef string_ref_rep<Allocator> string_ref_rep_type;
  217.   typedef _TYPENAME string_ref_rep<Allocator>::size_type size_type;
  218.   
  219. public:
  220.   _EXPLICIT string_ref (long initRef = 0) 
  221.     :  string_ref_rep<Allocator>( (unsigned long)initRef - 1)
  222.   { ; }
  223.  
  224.   string_ref (const string_ref<charT,traits,Allocator>& ref)
  225.     : string_ref_rep<Allocator>(ref.refs_)
  226.   { ; }
  227.   ~string_ref() { ; }
  228.  
  229. private:
  230.   unsigned references () const { return string_ref_rep<Allocator>::refs_+1; }
  231.  
  232.   void setRefCount (unsigned r)       
  233.   { 
  234. #ifdef _RWSTD_NO_TEST_AND_SET
  235. #ifdef _RWSTD_MULTI_THREAD
  236.       _RWSTDGuard guard(this->mutex_);
  237. #endif
  238. #endif /* _RWSTD_NO_TEST_AND_SET */
  239.       _RWSTD_MT_SET(refs_,r-1);
  240.   }
  241.  
  242.   void addReference ()
  243.   { 
  244. #ifdef _RWSTD_NO_TEST_AND_SET
  245. #ifdef _RWSTD_MULTI_THREAD
  246.       _RWSTDGuard guard(this->mutex_);
  247. #endif
  248. #endif /* _RWSTD_NO_TEST_AND_SET */
  249.        _RWSTD_MT_INCREMENT(refs_);
  250.   }
  251.   unsigned  removeReference ()                
  252.   {
  253. #ifdef _RWSTD_NO_TEST_AND_SET
  254. #ifdef _RWSTD_MULTI_THREAD
  255.       _RWSTDGuard guard(this->mutex_);
  256. #endif
  257. #endif /* _RWSTD_NO_TEST_AND_SET */
  258.       return unSafeRemoveReference();
  259.   }
  260.   unsigned  unSafeRemoveReference ()                
  261.   {
  262.       _RWSTD_MT_DECREMENT(refs_);
  263.       return refs_+1;
  264.   }
  265.   void can_ref(bool b)
  266.   {
  267. #ifdef _RWSTD_NO_TEST_AND_SET
  268. #ifdef _RWSTD_MULTI_THREAD
  269.       _RWSTDGuard guard(this->mutex_);
  270. #endif
  271.         __can_ref_ = b;
  272. #else
  273.         _RWSTD_MT_SET(can_ref_,b ? 1 : 0);
  274. #endif /* _RWSTD_NO_TEST_AND_SET */
  275.   }
  276.   bool can_ref()
  277.   {
  278.       return can_ref_;
  279.   }
  280.  
  281.   size_type length         () const           { return string_ref_rep<Allocator>::nchars_; }
  282.   size_type getCapac       () const           { return string_ref_rep<Allocator>::capacity_;}
  283.  
  284.   charT*    data           () const
  285.   {
  286. #ifdef _RWSTD_NO_STATIC_CAST
  287.     return (charT*)(this+1);
  288. #else
  289.     return reinterpret_cast<charT*>(const_cast<string_ref<charT, traits, Allocator>*>(this+1));
  290. #endif
  291.   }
  292.   charT&   operator[]     (size_type i)      
  293.   { 
  294.     return (_RWSTD_REINTERPRET_CAST(charT*,(this+1)))[i]; 
  295.   }
  296.   const charT&  operator[]     (size_type i) const
  297.   {
  298.     return ((charT*)(this+1))[i];
  299.   }
  300. #ifndef _RWSTD_NO_NAMESPACE
  301.   friend class std::basic_string<charT, traits, Allocator>;
  302. #else
  303.   friend class basic_string<charT, traits, Allocator>;
  304. #endif
  305. };
  306.  
  307.  
  308. #ifndef _RWSTD_NO_NAMESPACE
  309. } // End of __rwstd 
  310.  
  311. namespace std {
  312. #endif
  313.  
  314. template <class charT, class traits , class Allocator >
  315. class _RWSTDExportTemplate basic_string
  316. {
  317.   public:
  318.  
  319.     //
  320.     // types
  321.     //
  322.     typedef traits                               traits_type;
  323.     typedef _TYPENAME traits::char_type          value_type;
  324.     typedef Allocator                            allocator_type;
  325.  
  326.   private:
  327.  
  328. #ifdef _RWSTD_ALLOCATOR
  329.     typedef _TYPENAME Allocator::rebind<charT>::other  value_alloc_type;
  330.     typedef _TYPENAME Allocator::rebind<__RWSTD::string_ref<charT,
  331.                           traits,Allocator> >::other  ref_alloc_type;
  332. #else
  333.     typedef allocator_interface<Allocator,charT>      
  334.                 value_alloc_type;
  335.     typedef allocator_interface<Allocator,
  336.                  __RWSTD::string_ref<charT,traits,Allocator> >  ref_alloc_type;
  337. #endif
  338.   
  339.   public:
  340.  
  341. #ifndef _RWSTD_NO_COMPLICATED_TYPEDEF
  342.     typedef _TYPENAME _RWSTD_ALLOC_SIZE_TYPE            size_type;
  343.     typedef _TYPENAME _RWSTD_ALLOC_DIFF_TYPE            difference_type;
  344.     typedef _TYPENAME value_alloc_type::reference       reference;
  345.     typedef _TYPENAME value_alloc_type::const_reference const_reference;
  346.     typedef _TYPENAME value_alloc_type::pointer         pointer;
  347.     typedef _TYPENAME value_alloc_type::const_pointer   const_pointer;
  348.     typedef _TYPENAME value_alloc_type::pointer         iterator;
  349.     typedef _TYPENAME value_alloc_type::const_pointer   const_iterator;
  350. #else
  351.     typedef size_t                            size_type;
  352.     typedef ptrdiff_t                         difference_type;
  353.     typedef charT&                            reference;
  354.     typedef const charT&                      const_reference;
  355.     typedef charT*                            pointer;
  356.     typedef const charT*                      const_pointer;
  357.     typedef charT*                            iterator;
  358.     typedef const charT*                      const_iterator;
  359. #endif  //_RWSTD_NO_COMPLICATED_TYPEDEF
  360.  
  361.     typedef _STD::reverse_iterator<const_iterator, value_type,
  362.                     const_reference, const_pointer,
  363.                     difference_type>   const_reverse_iterator;
  364.     typedef _STD::reverse_iterator<iterator, value_type,
  365.                     reference, pointer,
  366.                     difference_type>         reverse_iterator;
  367.  
  368. #ifdef _RWSTD_MSC22_STATIC_INIT_BUG
  369. #define npos (size_type)-1
  370. #else
  371.     static const size_type npos;
  372. #endif
  373.  
  374.     inline _EXPLICIT basic_string (const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  375. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS 
  376.     inline basic_string (void);
  377. #endif
  378.  
  379.     inline basic_string (const basic_string<charT, traits, Allocator>&);
  380.     basic_string (const basic_string<charT, traits, Allocator>&, size_type,
  381.                   size_type = npos);
  382.     basic_string (const charT*, size_type, const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  383.     basic_string (const charT*, const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  384.     basic_string (size_type, charT, const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  385.  
  386. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  387.     basic_string (const charT*, size_type); 
  388.     _EXPLICIT basic_string (const charT*); 
  389.     basic_string (size_type, charT); 
  390. #endif
  391.  
  392. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  393.     template <class InputIterator>
  394.       basic_string (InputIterator, InputIterator, const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  395. #else
  396.     basic_string (const charT*, const charT*, const Allocator& _RWSTD_DEFAULT_ARG(Allocator()));
  397. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  398.     basic_string (const charT*, const charT*);
  399. #endif
  400. #endif
  401.  
  402.     inline ~basic_string ();
  403.  
  404.     basic_string<charT, traits, Allocator>& operator= (const basic_string<charT, traits, Allocator>&);
  405.     basic_string<charT, traits, Allocator>& operator= (const charT*);
  406.     basic_string<charT, traits, Allocator>& operator= (charT);
  407.  
  408.     //
  409.     // iterators
  410.     //
  411.     iterator       begin ()        { cow(); can_ref(false); return data_;          }
  412.     const_iterator begin () const  { return data_;          }
  413.     iterator       end   ()        { cow(); can_ref(false); return data_+length(); }
  414.     const_iterator end   () const  { return data_+length(); }
  415.  
  416.     reverse_iterator rbegin ()
  417.     {
  418.         reverse_iterator tmp(end()); return tmp;
  419.     }
  420.     const_reverse_iterator rbegin () const
  421.     {
  422.         const_reverse_iterator tmp(end()); return tmp;
  423.     }
  424.     reverse_iterator rend ()
  425.     {
  426.         reverse_iterator tmp(begin()); return tmp;
  427.     }
  428.     const_reverse_iterator rend () const
  429.     {
  430.         const_reverse_iterator tmp(begin()); return tmp;
  431.     }
  432.  
  433.     //
  434.     // capacity
  435.     //
  436.     inline size_type length () const;
  437.     size_type size () const      { return length(); }
  438.     size_type max_size () const
  439.     {
  440.         return npos - sizeof(__RWSTD::string_ref_rep<Allocator>)-2;
  441.     }
  442.     void resize (size_type, charT);
  443.     void resize (size_type);
  444.     size_type capacity () const;
  445.     void reserve (size_type=0);
  446.     bool empty () const  { return length() == 0; }
  447.  
  448.     //
  449.     // element access
  450.     //
  451.     const_reference operator[] (size_type) const;
  452.     reference       operator[] (size_type);
  453.     const_reference at (size_type) const;
  454.     reference       at (size_type);
  455.  
  456.     //
  457.     // modifiers
  458.     //
  459.     basic_string<charT, traits, Allocator>& operator+= (const basic_string<charT, traits, Allocator>&);
  460.     basic_string<charT, traits, Allocator>& operator+= (const charT*);
  461.     basic_string<charT, traits, Allocator>& operator+= (charT);
  462.  
  463.     basic_string<charT, traits, Allocator>& append (
  464.                      const  basic_string<charT, traits, Allocator>&);
  465.     basic_string<charT, traits, Allocator>& append (
  466.                      const basic_string<charT, traits, Allocator>&,
  467.                      size_type, 
  468.                      size_type);
  469.     basic_string<charT, traits, Allocator>& append (const charT*, size_type);
  470.     basic_string<charT, traits, Allocator>& append (const charT*);
  471.     basic_string<charT, traits, Allocator>& append (size_type, charT);
  472.  
  473. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  474.     template<class InputIterator>
  475.     basic_string<charT, traits, Allocator>& append (InputIterator,
  476.                                                     InputIterator);
  477. #else
  478.     basic_string<charT, traits, Allocator>& append (const charT*,
  479.                                                     const charT*);
  480. #endif
  481.  
  482.     basic_string<charT, traits, Allocator>& assign (
  483.                      const basic_string<charT, traits, Allocator>&);
  484.     basic_string<charT, traits, Allocator>& assign (
  485.                      const basic_string<charT, traits, Allocator>&,
  486.                      size_type, 
  487.                      size_type);
  488.     basic_string<charT, traits, Allocator>& assign (const charT*, size_type);
  489.     basic_string<charT, traits, Allocator>& assign (const charT*);
  490.     basic_string<charT, traits, Allocator>& assign (size_type, charT);
  491.  
  492. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  493.     template<class InputIterator>
  494.     basic_string<charT, traits, Allocator>& assign (InputIterator,
  495.                                                     InputIterator);
  496. #else
  497.     basic_string<charT, traits, Allocator>& assign (const charT*,
  498.                                                     const charT*);   
  499. #endif
  500.   
  501.     basic_string<charT, traits, Allocator>& insert (size_type,
  502.                      const basic_string<charT, traits, Allocator>&);
  503.     basic_string<charT, traits, Allocator>& insert (
  504.                      size_type,
  505.                      const basic_string<charT, traits, Allocator>&,
  506.                      size_type, 
  507.                      size_type);
  508.     basic_string<charT, traits, Allocator>& insert (
  509.                      size_type,
  510.                      const charT*, 
  511.                      size_type);
  512.     basic_string<charT, traits, Allocator>& insert (size_type, const charT*);
  513.     basic_string<charT, traits, Allocator>& insert (size_type,size_type,charT);
  514.     void insert (iterator, size_type, charT);
  515.     iterator insert (iterator pos, charT c = charT())
  516.     { 
  517.         return replace_aux(pos-begin(), 0, basic_string<charT, traits, Allocator>(1,c)); 
  518.     }
  519. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  520.     template<class InputIterator>
  521.     void insert (iterator, InputIterator, InputIterator);
  522. #else
  523.     void insert (iterator, const charT*, const charT*);
  524. #endif
  525.     
  526.     basic_string<charT, traits, Allocator>& erase (size_type = 0,
  527.                                                     size_type = npos);
  528.  
  529.     iterator erase (iterator it) 
  530.     { 
  531.        return replace(it - begin(),1,NULL,0,0,0);
  532.     }
  533.     iterator erase (iterator first, iterator last) 
  534.     {  
  535.        return replace(first - begin(),last-first,NULL,0,0,0);
  536.     }
  537.  
  538. private:  
  539.     //
  540.     // Used for effiency
  541.     //
  542.     _TYPENAME 
  543.     basic_string<charT, traits, Allocator>::iterator replace (size_type, 
  544.                                                               size_type, 
  545.                                                               const charT*,
  546.                                                               size_type,
  547.                                                               size_type,
  548.                                                               size_type);
  549.     _TYPENAME 
  550.     basic_string<charT, traits, Allocator>::iterator replace_aux (
  551.                               size_type, 
  552.                               size_type,
  553.                               const basic_string<charT, traits, Allocator>&,
  554.                               size_type =0,
  555.                               size_type =npos);
  556. public:
  557.     basic_string<charT, traits, Allocator>& replace (size_type, 
  558.                                                      size_type,
  559.                                                      const basic_string<charT, traits, Allocator>&);
  560.     basic_string<charT, traits, Allocator>& replace (size_type, 
  561.                                                      size_type,
  562.                                                      const basic_string<charT, traits, Allocator>&,
  563.                                                      size_type, 
  564.                                                      size_type);
  565.     basic_string<charT, traits, Allocator>& replace (size_type, 
  566.                                                      size_type, 
  567.                                                      const charT*, 
  568.                                                      size_type);
  569.     basic_string<charT, traits, Allocator>& replace (size_type,
  570.                                                      size_type, 
  571.                                                      const charT*);
  572.     basic_string<charT, traits, Allocator>& replace (size_type,
  573.                                                      size_type,
  574.                                                      size_type,
  575.                                                      charT);
  576.     basic_string<charT, traits, Allocator>& replace (iterator,
  577.                                                      iterator,
  578.                                                      const basic_string<charT, traits, Allocator>&);
  579.     basic_string<charT, traits, Allocator>& replace (iterator,
  580.                                                     iterator,
  581.                                                      const charT*,
  582.                                                      size_type);
  583.     basic_string<charT, traits, Allocator>& replace (iterator,
  584.                                                      iterator,
  585.                                                      const charT*);
  586.     basic_string<charT, traits, Allocator>& replace (iterator,
  587.                                                      iterator,
  588.                                                      size_type,
  589.                                                      charT);
  590. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  591.     template<class InputIterator>
  592.     basic_string<charT, traits, Allocator>& replace (iterator, iterator, 
  593.                                                      InputIterator,
  594.                                                      InputIterator);
  595. #else
  596.     basic_string<charT, traits, Allocator>& replace (iterator, iterator, 
  597.                                                      const charT*,
  598.                                                      const charT*);
  599. #endif
  600.  
  601.     size_type copy (charT*, size_type, size_type = 0);
  602.     basic_string<charT, traits, Allocator> copy () const; // Returns deep copy
  603.     void swap(basic_string<charT, traits, Allocator>& s)
  604.     {
  605.         charT * temp = data_; data_ = s.data_; s.data_ = temp;
  606.     }
  607.  
  608.     //
  609.     // string operations
  610.     //
  611.     inline const charT* c_str () const;
  612.     inline const charT* data  () const;
  613.     const allocator_type& get_allocator() const
  614.     {
  615.       return alloc_;
  616.     }
  617.  
  618.     size_type find (const basic_string<charT, traits, Allocator>&,
  619.                     size_type = 0) const;
  620.     size_type find (const charT*, size_type, size_type) const;
  621.     size_type find (const charT*, size_type = 0) const;
  622.     size_type find (charT, size_type = 0) const;
  623.  
  624.     size_type rfind (const basic_string<charT, traits, Allocator>&,
  625.                      size_type = npos) const;
  626.     size_type rfind (const charT*, size_type, size_type) const;
  627.     size_type rfind (const charT*, size_type = npos) const;
  628.     size_type rfind (charT, size_type = npos) const;
  629.  
  630.     size_type find_first_of (const basic_string<charT, traits, Allocator>&,
  631.                              size_type = 0) const;
  632.     size_type find_first_of (const charT*, size_type, size_type) const;
  633.     size_type find_first_of (const charT*, size_type = 0) const;
  634.     size_type find_first_of (charT, size_type = 0) const;
  635.  
  636.     size_type find_last_of (const basic_string<charT, traits, Allocator>&,
  637.                             size_type = npos) const;
  638.     size_type find_last_of (const charT*, size_type, size_type) const;
  639.     size_type find_last_of (const charT*, size_type = npos) const;
  640.     size_type find_last_of (charT, size_type = npos) const;
  641.  
  642.     size_type find_first_not_of (const basic_string<charT, traits, Allocator>&,
  643.                                  size_type = 0) const;
  644.     size_type find_first_not_of (const charT*, size_type ,
  645.                                  size_type) const;
  646.     size_type find_first_not_of (const charT*, size_type = 0) const;
  647.     size_type find_first_not_of (charT, size_type = 0) const;
  648.  
  649.     size_type find_last_not_of (const basic_string<charT, traits, Allocator>&,
  650.                                 size_type = npos) const;
  651.     size_type find_last_not_of (const charT*, size_type, size_type) const;
  652.     size_type find_last_not_of (const charT*, size_type = npos) const;
  653.     size_type find_last_not_of (charT, size_type = npos) const;
  654.   
  655.     basic_string<charT, traits, Allocator> substr (size_type = 0,
  656.                                                    size_type = npos) const;
  657.   
  658.     int compare(size_type, size_type,
  659.                 const basic_string<charT, traits, Allocator>&,
  660.                 size_type, size_type) const;
  661.     int compare(size_type, size_type,
  662.                 const basic_string<charT, traits, Allocator>&) const;
  663.     int compare(const basic_string<charT, traits, Allocator>&) const;
  664.     int compare (size_type, size_type, const charT*, size_type) const;
  665.     int compare (size_type, size_type, const charT*) const;
  666.     int compare (const charT*) const;
  667.  
  668.  protected:
  669.  
  670.     size_type getCapac () const { return pref()->getCapac(); }
  671.  
  672.     void clobber (size_type); // Remove old contents
  673.     void cow ()               // Do copy on write as necessary
  674.     { 
  675.         if (pref()->references() > 1) 
  676.           clone(); 
  677.     }
  678.     void cow (size_type nc)     // Do copy on write w/ new capacity
  679.     { 
  680.       if (pref()->references() > 1 || getCapac() < nc)
  681.         clone(nc);
  682.     }
  683.     bool can_ref() { return pref()->can_ref(); }
  684.     void can_ref(bool b) { pref()->can_ref(b); }
  685.  
  686.  private:
  687.  
  688.     typedef __RWSTD::string_ref<charT,traits,Allocator> string_ref_type;
  689.  
  690.     static charT eos () { return charT(0); }
  691.   
  692.     //
  693.     // Make a distinct copy of self
  694.     //
  695.     void clone (); 
  696.     //
  697.     // Make a distinct copy w/ new capacity nc
  698.     //
  699.     void clone (size_type nc);
  700.  
  701.     string_ref_type *  pref () const
  702.     { 
  703. #ifdef _RWSTD_SUNPRO_ANACHRONISM
  704.       return (string_ref_type*)data_ - 1;
  705. #else
  706.       return _RWSTD_STATIC_CAST(string_ref_type*,((_RWSTD_REINTERPRET_CAST(string_ref_type*,data_)) - 1)); 
  707. #endif
  708.     }
  709.  
  710.     //
  711.     // Disconnect from ref, maybe delete it.
  712.     //
  713.     void      unLink          ();   
  714.  
  715.     //
  716.     // Null string ref
  717.     //
  718. #ifndef _RWSTD_NO_STATIC_DEF3
  719.     static const __RWSTD::null_string_ref_rep<charT, traits, 
  720.                                Allocator> nullref;
  721. #endif
  722.  
  723.     static __RWSTD::string_ref<charT, traits, Allocator> * getNullRep ()
  724. #ifndef _RWSTD_NO_STATIC_DEF3
  725.   {
  726. #ifdef _RWSTD_NO_STATIC_CAST
  727. #ifndef HPPA_WA
  728.     return (__RWSTD::string_ref<charT, traits, Allocator> *)&nullref;
  729. #else
  730.     return (__RWSTD::string_ref<charT, traits, Allocator> *) (void *) &nullref;
  731. #endif /* HPPA_WA */
  732. #else
  733.    return reinterpret_cast<__RWSTD::string_ref<charT, traits, Allocator> *>
  734.      (const_cast<__RWSTD::null_string_ref_rep<charT, traits, Allocator> *>(&nullref));
  735. #endif
  736.   }
  737. #else
  738.     { 
  739.       if (!__RWSTD::nullref_initialized)
  740.       {
  741.         new (&__RWSTD::nullref) __RWSTD::null_string_ref_rep<charT, traits,Allocator>();
  742.         __RWSTD::nullref_initialized = 1;
  743.       }
  744.       return (__RWSTD::string_ref<charT, traits, Allocator> *) &__RWSTD::nullref[0]; 
  745.     }
  746. #endif
  747.  
  748.     __RWSTD::string_ref<charT, traits, Allocator> * getRep (size_type capac, 
  749.                                                    size_type nchar);
  750.  
  751.  
  752.     allocator_type       alloc_;
  753.     charT*    data_;                   
  754. };
  755.  
  756.  
  757. //
  758. // Standard Type Definitions
  759. //
  760. typedef basic_string<char, char_traits<char>, allocator<char> >
  761.   string;
  762.  
  763. #ifndef _RWSTD_NO_WIDE_CHAR
  764. typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >
  765.   wstring;
  766. #endif
  767.  
  768.  
  769.  
  770. //
  771. // The following has to go after the declaration of the string
  772. // classes because of cross references.
  773. //
  774.  
  775. #ifndef _RWSTD_NO_NAMESPACE
  776. }
  777. #endif
  778.  
  779. #ifdef _RW_STD_EXCEPT
  780. #ifndef _RWSTD_HEADER_REQUIRES_HPP
  781. #include <stdexcept>
  782. #else
  783. #include <stdexcept.hpp>
  784. #endif
  785. #endif
  786.  
  787. #if defined(_RWSTD_NO_DESTROY_BUILTIN) || defined(_RWSTD_NO_DESTROY_NONBUILTIN)
  788.  
  789. #ifndef _RWSTD_NO_NAMESPACE
  790. namespace __rwstd {
  791. #endif
  792. //
  793. // Specializations for STL destroy
  794. //
  795. inline void __destroy (string**)    {;}
  796. inline void __destroy (string***)   {;}
  797. inline void __destroy (string****)  {;}
  798. #ifndef _RWSTD_NO_WIDE_CHAR
  799. inline void __destroy (wstring**)   {;}
  800. inline void __destroy (wstring***)  {;}
  801. inline void __destroy (wstring****) {;}
  802. #endif
  803.  
  804. #ifndef _RWSTD_NO_NAMESPACE
  805. }
  806. #endif
  807. #endif
  808.  
  809. #ifndef _RWSTD_NO_NAMESPACE
  810. namespace std {
  811. #endif
  812.  
  813. //
  814. // Inline member functions for class basic_string
  815. //
  816.  
  817. template <class charT, class traits , class Allocator  >
  818. inline void basic_string<charT, traits, Allocator>::unLink()
  819. {
  820.     if (pref()->removeReference() == 0) 
  821.     {
  822.       ref_alloc_type(alloc_).destroy(pref());
  823.       value_alloc_type(alloc_).
  824.             deallocate(_RWSTD_REINTERPRET_CAST(charT*,pref()),length());
  825.     }
  826. }
  827.  
  828. template <class charT, class traits , class Allocator  >
  829. inline basic_string<charT, traits, Allocator>
  830.   ::basic_string (const Allocator& alloc) : alloc_(alloc)
  831. {
  832.     data_ = getNullRep()->data();
  833.     getNullRep()->addReference();
  834. }
  835.  
  836. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  837. template <class charT, class traits , class Allocator  >
  838. inline basic_string<charT, traits, Allocator>
  839.   ::basic_string (void) : alloc_(Allocator())
  840. {
  841.     data_ = getNullRep()->data();
  842.     getNullRep()->addReference();
  843. }
  844. #endif
  845.  
  846. template <class charT, class traits , class Allocator  >
  847. inline
  848. basic_string<charT, traits, Allocator>
  849.   ::basic_string (const basic_string<charT, traits, Allocator> & s)
  850. {            
  851.     if ( s.pref()->can_ref() )
  852.     {                    
  853.       alloc_ = s.get_allocator();
  854.       data_ = s.data_;
  855.       pref()->addReference();
  856.     }
  857.     else
  858.     {
  859.       size_type n = s.length();
  860.       data_  = getRep(n, n)->data();
  861.  
  862.       traits::copy(data_, s.c_str(), n);
  863.     }
  864. }
  865.  
  866. template <class charT, class traits , class Allocator  >
  867. inline basic_string<charT, traits, Allocator>::~basic_string ()
  868. {
  869.     unLink();
  870. }
  871.  
  872. template <class charT, class traits , class Allocator  >
  873. inline basic_string<charT, traits, Allocator> &
  874. basic_string<charT, traits, Allocator>::operator= (charT c)
  875. {
  876.     return *this = basic_string<charT, traits, Allocator>(1,c);
  877. }
  878.  
  879. template <class charT, class traits , class Allocator  >
  880. inline basic_string<charT, traits, Allocator> &
  881. basic_string<charT, traits, Allocator>::operator+= (const basic_string<charT, traits, Allocator>& s)
  882. {
  883.     return append(s);
  884. }
  885.  
  886. template <class charT, class traits , class Allocator  >
  887. inline basic_string<charT, traits, Allocator> &
  888. basic_string<charT, traits, Allocator>::operator+= (const charT* s)
  889. {
  890.     return append(s);
  891. }
  892.  
  893. template <class charT, class traits , class Allocator  >
  894. inline basic_string<charT, traits, Allocator> &
  895. basic_string<charT, traits, Allocator>::operator+= (charT c)
  896. {
  897.     return append((size_type) 1, c);
  898. }
  899.  
  900. template <class charT, class traits , class Allocator  >
  901. inline basic_string<charT, traits, Allocator> &
  902. basic_string<charT, traits, Allocator>::append (const charT* s, size_type n)
  903. {
  904.     replace(size(),0,s,n,0,n);
  905.     return *this;
  906. }
  907.  
  908. template <class charT, class traits , class Allocator  >
  909. inline basic_string<charT, traits, Allocator> &
  910. basic_string<charT, traits, Allocator>::append (const charT* s)
  911. {
  912.     replace(size(),0,s);
  913.     return *this;
  914. }
  915.  
  916. template <class charT, class traits , class Allocator  >
  917. inline basic_string<charT, traits, Allocator> &
  918. basic_string<charT, traits, Allocator>::append (size_type n, charT c)
  919. {
  920.     return append(basic_string<charT,traits,Allocator>(n,c));
  921. }
  922.  
  923. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  924. template<class charT, class traits , class Allocator >
  925. template<class InputIterator>
  926. inline basic_string<charT, traits, Allocator>& 
  927. basic_string<charT, traits, Allocator>::append (InputIterator first, 
  928.                                                 InputIterator last )
  929. {
  930.     return append(basic_string<charT, traits, Allocator>(first, last));
  931. }
  932. #else
  933. template <class charT, class traits , class Allocator  >
  934. inline basic_string<charT, traits, Allocator>& 
  935. basic_string<charT, traits, Allocator>::append (const charT* first, 
  936.                                                 const charT* last)
  937. {
  938.     replace(size(),0,first,last-first,0,last-first);
  939.     return *this;
  940. }
  941. #endif
  942.  
  943. template <class charT, class traits , class Allocator  >
  944. inline basic_string<charT, traits, Allocator> &
  945. basic_string<charT, traits, Allocator>::assign (const charT* s, size_type n)
  946. {
  947.     replace(0, length(), s, n, 0, n);
  948.     return *this;
  949. }
  950.  
  951. template <class charT, class traits , class Allocator  >
  952. inline basic_string<charT, traits, Allocator> &
  953. basic_string<charT, traits, Allocator>::assign (const charT* s)
  954. {
  955.     size_type len = traits::length(s);
  956.     replace(0, length(), s, len, 0, len);
  957.     return *this;
  958. }
  959.  
  960. template <class charT, class traits , class Allocator  >
  961. inline basic_string<charT, traits, Allocator> &
  962. basic_string<charT, traits, Allocator>::assign (size_type n, charT c)
  963. {
  964.     return assign(basic_string<charT,traits,Allocator>(n,c));
  965. }
  966.  
  967. #ifndef _RWSTD_NO_MEMBER_TEMPLATES /* _RW_STD_IOSTREAM */
  968. template<class charT, class traits , class Allocator >
  969. template<class InputIterator>
  970. inline basic_string<charT, traits, Allocator>& 
  971. basic_string<charT, traits, Allocator>::assign (InputIterator first, 
  972.                                                 InputIterator last)
  973. {
  974.     return assign(basic_string<charT, traits, Allocator>(first, last));
  975. }
  976. #else
  977. template <class charT, class traits , class Allocator  >
  978. inline basic_string<charT, traits, Allocator>& 
  979. basic_string<charT, traits, Allocator>::assign (const charT* first, 
  980.                                                 const charT* last)
  981. {
  982.     replace(0,length(),first,last-first,0,last-first);
  983.     return *this;
  984. }
  985. #endif
  986.  
  987. template <class charT, class traits , class Allocator  >
  988. inline basic_string<charT, traits, Allocator> &
  989. basic_string<charT, traits, Allocator>::insert (size_type pos,
  990.                                                 const charT* s,
  991.                                                 size_type n)
  992. {
  993.     replace(pos, 0, s, n, 0, n);
  994.     return *this;
  995. }
  996.  
  997. template <class charT, class traits , class Allocator  >
  998. inline basic_string<charT, traits, Allocator> &
  999. basic_string<charT, traits, Allocator>::insert (size_type pos, const charT* s)
  1000. {
  1001.     size_type len = traits::length(s);
  1002.     replace(pos, 0, s, len, 0, len);
  1003.     return *this;
  1004. }
  1005.  
  1006. template <class charT, class traits , class Allocator  >
  1007. inline basic_string<charT, traits, Allocator> &
  1008. basic_string<charT, traits, Allocator>::insert(size_type pos,
  1009.                                                size_type n,
  1010.                                                charT c)
  1011. {
  1012.     return insert(pos, basic_string<charT,traits,Allocator>(n,c));
  1013. }
  1014.  
  1015. template <class charT, class traits , class Allocator  >
  1016. inline void 
  1017. basic_string<charT, traits, Allocator>::insert (
  1018.                    basic_string<charT, traits, Allocator>::iterator p,
  1019.                    size_type n,
  1020.                    charT c)
  1021. {
  1022.     replace_aux(p-begin(),0,basic_string<charT,traits,Allocator>(n,c));
  1023. }
  1024.  
  1025. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  1026. template<class charT, class traits , class Allocator >
  1027. template<class InputIterator>
  1028. inline void 
  1029. basic_string<charT, traits, Allocator>::insert (
  1030.                    basic_string<charT, traits, Allocator>::iterator p, 
  1031.                    InputIterator first,
  1032.                    InputIterator last)
  1033. {
  1034.     replace(p-begin(), 0, basic_string<charT, traits, Allocator>(first, last));
  1035. }
  1036. #else
  1037. template <class charT, class traits , class Allocator  >
  1038. inline void 
  1039. basic_string<charT, traits, Allocator>::insert (
  1040.                    basic_string<charT, traits, Allocator>::iterator p, 
  1041.                    const charT* first,
  1042.                    const charT* last)
  1043. {
  1044.     replace(p-begin(),0,first,last-first,0,last-first);
  1045. }
  1046. #endif
  1047.  
  1048. template <class charT, class traits , class Allocator  >
  1049. inline basic_string<charT, traits, Allocator> &
  1050. basic_string<charT, traits, Allocator>::erase (size_type pos, size_type n)
  1051. {
  1052.     _RWSTD_THROW(pos > length(), out_of_range, 
  1053.                  __RWSTD::rwse_StringIndexOutOfRange);
  1054.     size_type len = length() - pos;
  1055.     charT tmp[1];
  1056.     *tmp = 0;
  1057.     return replace(pos,n < len ? n : len, tmp,0);
  1058. }
  1059.  
  1060. template <class charT, class traits , class Allocator  >
  1061. inline basic_string<charT, traits, Allocator> &
  1062. basic_string<charT, traits, Allocator>::replace (size_type pos1,
  1063.                                                  size_type n1,
  1064.                                                  const basic_string<charT, traits, Allocator> & str, 
  1065.                                                  size_type pos2,
  1066.                                                  size_type n2)
  1067. {
  1068.     replace(pos1, n1, str.data(), str.length(), pos2, n2);
  1069.     return *this;
  1070. }
  1071.  
  1072. template <class charT, class traits , class Allocator  >
  1073. inline basic_string<charT, traits, Allocator> &
  1074. basic_string<charT, traits, Allocator>::replace (
  1075.                  size_type pos1,
  1076.                  size_type n1,
  1077.                  const basic_string<charT, traits, Allocator> & str)
  1078. {
  1079.     replace(pos1, n1, str.data(), str.length(),0,str.length());
  1080.     return *this;
  1081. }
  1082.  
  1083. template <class charT, class traits , class Allocator  >
  1084. inline _TYPENAME basic_string<charT, traits, Allocator>::iterator
  1085. basic_string<charT, traits, Allocator>::replace_aux (size_type pos1,
  1086.                                                      size_type n1,
  1087.                                                      const basic_string<charT, traits, Allocator> & str, 
  1088.                                                      size_type pos2,
  1089.                                                      size_type n2)
  1090. {
  1091.     return replace(pos1, n1, str.data(), str.length(), pos2, n2);
  1092. }
  1093.  
  1094. template <class charT, class traits , class Allocator  >
  1095. inline basic_string<charT, traits, Allocator> &
  1096. basic_string<charT, traits, Allocator>::replace (size_type pos,
  1097.                                                  size_type n1,
  1098.                                                  const charT* s,
  1099.                                                  size_type n2)
  1100. {
  1101.     replace(pos, n1, s, n2, 0, n2);
  1102.     return *this;
  1103. }
  1104.  
  1105. template <class charT, class traits , class Allocator  >
  1106. inline basic_string<charT, traits, Allocator> &
  1107. basic_string<charT, traits, Allocator>::replace (size_type pos,
  1108.                                                  size_type n1,
  1109.                                                  const charT* s)
  1110. {
  1111.     size_type len = traits::length(s);
  1112.     replace(pos, n1, s, len, 0, len);
  1113.     return *this;
  1114. }
  1115.  
  1116. template <class charT, class traits , class Allocator  >
  1117. inline basic_string<charT, traits, Allocator> &
  1118. basic_string<charT, traits, Allocator>::replace (size_type pos,
  1119.                                                  size_type n,
  1120.                                                  size_type n2,
  1121.                                                  charT c)
  1122. {
  1123.     return replace(pos, n, basic_string<charT, traits, Allocator>(n2,c));
  1124. }
  1125.  
  1126. template <class charT, class traits , class Allocator  >
  1127. inline basic_string<charT, traits, Allocator>& 
  1128. basic_string<charT, traits, Allocator>::replace (
  1129.               basic_string<charT, traits, Allocator>::iterator first,
  1130.               basic_string<charT, traits, Allocator>::iterator last,
  1131.               const basic_string<charT, traits, Allocator>& str)
  1132. {
  1133.     return replace(first - begin(), last - first, str);
  1134. }
  1135.  
  1136. template <class charT, class traits , class Allocator  >
  1137. inline basic_string<charT, traits, Allocator>& 
  1138. basic_string<charT, traits, Allocator>::replace (
  1139.               basic_string<charT, traits, Allocator>::iterator first, 
  1140.               basic_string<charT, traits, Allocator>::iterator last,
  1141.               const charT* s,
  1142.               size_type n)
  1143. {
  1144.     replace(first-begin(),last-first,s,n,0,n);
  1145.     return *this;
  1146. }
  1147.  
  1148. template <class charT, class traits , class Allocator  >
  1149. inline basic_string<charT, traits, Allocator>& 
  1150. basic_string<charT, traits, Allocator>::replace (
  1151.               basic_string<charT, traits, Allocator>::iterator first, 
  1152.               basic_string<charT, traits, Allocator>::iterator last,
  1153.               const charT* s)
  1154. {
  1155.     size_type len = traits::length(s);
  1156.     replace(first-begin(),last-first,s,len,0,len);
  1157.     return *this;
  1158. }
  1159.  
  1160. template <class charT, class traits , class Allocator  >
  1161. inline basic_string<charT, traits, Allocator>& 
  1162. basic_string<charT, traits, Allocator>::replace (
  1163.              basic_string<charT, traits, Allocator>::iterator first, 
  1164.              basic_string<charT, traits, Allocator>::iterator last,
  1165.              size_type n,
  1166.              charT c)
  1167. {
  1168.     return replace(first,last,basic_string<charT,traits,Allocator>(n,c));
  1169. }
  1170.  
  1171. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  1172. template<class charT, class traits , class Allocator >
  1173. template<class InputIterator>
  1174. inline basic_string<charT, traits, Allocator>& 
  1175. basic_string<charT, traits, Allocator>::replace (
  1176.             basic_string<charT, traits, Allocator>::iterator first1, 
  1177.             basic_string<charT, traits, Allocator>::iterator last1,
  1178.             InputIterator first2,
  1179.             InputIterator last2)
  1180. {
  1181.     return replace(first1,last1,
  1182.                    basic_string<charT,traits,Allocator>(first2,last2));
  1183. }
  1184. #else
  1185. template <class charT, class traits , class Allocator  >
  1186. inline basic_string<charT, traits, Allocator>& 
  1187. basic_string<charT, traits, Allocator>::replace (
  1188.             basic_string<charT, traits, Allocator>::iterator first1, 
  1189.             basic_string<charT, traits, Allocator>::iterator last1,
  1190.             const charT* first2,
  1191.             const charT* last2)
  1192. {
  1193.     replace(first1-begin(),last1-first1,first2,last2-first2,0,last2-first2);
  1194.     return *this;
  1195. }
  1196. #endif
  1197.  
  1198. template <class charT, class traits , class Allocator  >
  1199. inline _TYPENAME basic_string<charT, traits,Allocator>::const_reference 
  1200. basic_string<charT, traits, Allocator>::operator[] (size_type pos) const
  1201. {
  1202. #ifdef _RWSTD_BOUNDS_CHECKING
  1203.     _RWSTD_THROW(pos > size(),out_of_range,__RWSTD::rwse_PosBeyondEndOfString);
  1204. #endif
  1205.     return data_[pos];
  1206. }
  1207.  
  1208. template <class charT, class traits , class Allocator  >
  1209. inline _TYPENAME basic_string<charT, traits, Allocator>::reference
  1210. basic_string<charT, traits, Allocator>::operator[] (size_type pos)
  1211. {
  1212. #ifdef _RWSTD_BOUNDS_CHECKING
  1213.     _RWSTD_THROW(pos >= size(), out_of_range, 
  1214.                  __RWSTD::rwse_PosBeyondEndOfString);
  1215. #endif
  1216.     cow();
  1217.     can_ref(false);
  1218.     return data_[pos];
  1219. }
  1220.  
  1221. template <class charT, class traits , class Allocator  >
  1222. inline _TYPENAME basic_string<charT, traits, Allocator>::const_reference
  1223. basic_string<charT, traits, Allocator>::at (size_type pos) const
  1224. {
  1225.     _RWSTD_THROW(pos >= size(), out_of_range, 
  1226.                  __RWSTD::rwse_PosBeyondEndOfString);
  1227.     return data_[pos];
  1228. }
  1229.  
  1230. template <class charT, class traits , class Allocator  >
  1231. inline _TYPENAME basic_string<charT, traits, Allocator>::reference
  1232. basic_string<charT, traits, Allocator>::at (size_type pos)
  1233. {
  1234.     _RWSTD_THROW(pos >= size(), out_of_range, 
  1235.                  __RWSTD::rwse_PosBeyondEndOfString);
  1236.     cow();
  1237.     can_ref(false);
  1238.     return data_[pos];
  1239. }
  1240.  
  1241. template <class charT, class traits , class Allocator  >
  1242. inline const charT* basic_string<charT, traits, Allocator>::c_str () const
  1243. {
  1244.     return data_;
  1245. }
  1246.  
  1247. template <class charT, class traits , class Allocator  >
  1248. inline const charT* basic_string<charT, traits, Allocator>::data () const
  1249. {
  1250.   return data_;
  1251. }
  1252.  
  1253. template <class charT, class traits , class Allocator  >
  1254. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1255. basic_string<charT, traits, Allocator>::length () const
  1256. {
  1257.     return pref()->nchars_;
  1258. }
  1259.  
  1260. template <class charT, class traits , class Allocator  >
  1261. inline void
  1262. basic_string<charT, traits, Allocator>::resize (size_type n)
  1263. {
  1264.     resize(n, eos());
  1265. }
  1266.  
  1267. template <class charT, class traits , class Allocator  >
  1268. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1269. basic_string<charT, traits, Allocator>::capacity () const
  1270. {
  1271.     return getCapac();
  1272. }
  1273.  
  1274. template <class charT, class traits , class Allocator  >
  1275. inline void basic_string<charT, traits, Allocator>::reserve(size_type res_arg)
  1276. {
  1277.     if (res_arg > getCapac()) clone(res_arg);
  1278. }
  1279.  
  1280. template <class charT, class traits , class Allocator  >
  1281. inline basic_string<charT, traits, Allocator>
  1282. basic_string<charT, traits, Allocator>::copy () const
  1283. {
  1284.     basic_string<charT, traits, Allocator> temp(*this); // Make referenced copy
  1285.     temp.clone();   // Make a distinct copy
  1286.     return temp;
  1287. }
  1288.  
  1289. template <class charT, class traits, class Allocator >
  1290. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1291. basic_string<charT, traits, Allocator>::find (
  1292.   const basic_string<charT, traits, Allocator>& str,
  1293.   size_type                                     pos) const
  1294. {
  1295.     return find(str.c_str(),pos,str.length());
  1296. }
  1297.  
  1298. template <class charT, class traits , class Allocator  >
  1299. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1300. basic_string<charT, traits, Allocator>::find (const charT* s,
  1301.                                               size_type pos) const
  1302. {
  1303.     _RWSTD_THROW(s == 0, logic_error, __RWSTD::rwse_UnexpectedNullPtr);
  1304.     if (pos > length())
  1305.       return npos;
  1306.     const charT* p = __RWSTD::rw_traits<charT,traits>::find(data_+pos,s);
  1307.     return p ? p - data_ : npos;
  1308. }
  1309.  
  1310. template <class charT, class traits , class Allocator  >
  1311. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1312. basic_string<charT, traits, Allocator>::find (charT c, size_type pos) const
  1313. {
  1314.    if (pos > length())
  1315.      return npos;
  1316.    const charT* p =  traits::find(data_+pos,length()-pos,c);
  1317.    return p ? p - data_ : npos;
  1318. }
  1319.  
  1320. template <class charT, class traits, class Allocator >
  1321. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1322. basic_string<charT, traits, Allocator>::rfind (
  1323.   const basic_string<charT, traits, Allocator>& str,
  1324.   size_type                                     pos) const
  1325. {
  1326.     return rfind(str.c_str(), pos, str.length());
  1327. }
  1328.  
  1329. template <class charT, class traits , class Allocator  >
  1330. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1331. basic_string<charT, traits, Allocator>::rfind (const charT* s, size_type pos)
  1332. const
  1333. {  
  1334.     size_type len = traits::length(s);
  1335.     return rfind(s, pos,len);
  1336. }
  1337.  
  1338. template <class charT, class traits , class Allocator  >
  1339. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1340. basic_string<charT, traits, Allocator>::rfind (charT c, size_type pos) const
  1341. {
  1342.     if (pos > length())
  1343.       pos = length();
  1344.     const charT* p = __RWSTD::rw_traits<charT,traits>::rfind(data_,c,pos);
  1345.     return p ? p - data_ : npos;
  1346. }
  1347.  
  1348. template <class charT, class traits, class Allocator >
  1349. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1350. basic_string<charT, traits, Allocator>::find_first_of (
  1351.   const basic_string<charT, traits, Allocator>& str,
  1352.   size_type                                     pos) const
  1353. {
  1354.     return find_first_of(str.c_str(),pos,str.length());
  1355. }
  1356.  
  1357. template <class charT, class traits , class Allocator  >
  1358. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1359. basic_string<charT, traits, Allocator>::find_first_of (const charT* s,
  1360.                                                        size_type pos) const
  1361. {
  1362.     _RWSTD_THROW(s == 0, logic_error, __RWSTD::rwse_UnexpectedNullPtr);
  1363.     if (pos > length())
  1364.       return npos;
  1365.     size_type i = __RWSTD::rw_traits<charT,traits>::find_first_of(data_+pos,s) + pos;
  1366.     return i >= length() ? npos : i;
  1367. }
  1368.  
  1369. template <class charT, class traits , class Allocator  >
  1370. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1371. basic_string<charT, traits, Allocator>::find_first_of (charT c, size_type pos) const
  1372. {
  1373.     return find(c, pos);
  1374. }
  1375.  
  1376. template <class charT, class traits, class Allocator >
  1377. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1378. basic_string<charT, traits, Allocator>::find_last_of (
  1379.   const basic_string<charT, traits, Allocator>& str,
  1380.   size_type                                     pos) const
  1381. {
  1382.     return find_last_of(str.c_str(), pos,str.length());
  1383. }
  1384.  
  1385. template <class charT, class traits , class Allocator  >
  1386. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1387. basic_string<charT, traits, Allocator>::find_last_of (const charT* s,
  1388.                                                       size_type pos) const
  1389. {
  1390.     size_type len = traits::length(s);
  1391.     return find_last_of(s, pos,len);
  1392. }
  1393.  
  1394. template <class charT, class traits , class Allocator  >
  1395. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1396. basic_string<charT, traits, Allocator>::find_last_of (charT c, size_type pos)
  1397. const
  1398. {
  1399.     return rfind(c,pos);
  1400. }
  1401.  
  1402. template <class charT, class traits, class Allocator >
  1403. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1404. basic_string<charT, traits, Allocator>::find_first_not_of (
  1405.   const basic_string<charT, traits, Allocator>& str,
  1406.   size_type                                     pos) const
  1407. {
  1408.     return find_first_not_of(str.c_str(), pos, str.length());
  1409. }
  1410.  
  1411. template <class charT, class traits , class Allocator  >
  1412. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1413. basic_string<charT, traits, Allocator>::find_first_not_of (const charT* s,
  1414.                                                            size_type pos) const
  1415. {
  1416.     _RWSTD_THROW(s == 0, logic_error, __RWSTD::rwse_UnexpectedNullPtr);
  1417.     if (pos > length())
  1418.       return npos;
  1419.     size_type i = __RWSTD::rw_traits<charT,traits>::find_first_not_of(data_+pos,s) + pos;
  1420.     return i >= length() ? npos : i;
  1421. }
  1422.  
  1423. template <class charT, class traits , class Allocator  >
  1424. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1425. basic_string<charT, traits, Allocator>::find_first_not_of (charT c,
  1426.                                                            size_type pos) const
  1427. {
  1428.     charT tmp[2];
  1429.     *tmp = c;
  1430.     tmp[1] = 0;
  1431.     return find_first_not_of(tmp, pos);
  1432. }
  1433.  
  1434. template <class charT, class traits, class Allocator >
  1435. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1436. basic_string<charT, traits, Allocator>::find_last_not_of (
  1437.   const basic_string<charT, traits, Allocator>& str,
  1438.   size_type                                     pos) const
  1439. {
  1440.     return find_last_not_of(str.c_str(), pos, str.length());
  1441. }
  1442.  
  1443. template <class charT, class traits , class Allocator  >
  1444. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1445. basic_string<charT, traits, Allocator>::find_last_not_of (const charT* s,
  1446.                                                           size_type pos) const
  1447. {
  1448.     size_type len = traits::length(s);
  1449.     return find_last_not_of(s, pos, len);
  1450. }
  1451.  
  1452. template <class charT, class traits , class Allocator  >
  1453. inline _TYPENAME basic_string<charT, traits, Allocator>::size_type
  1454. basic_string<charT, traits, Allocator>::find_last_not_of (charT c,
  1455.                                                           size_type pos) const
  1456. {
  1457.     charT tmp[2];
  1458.     *tmp = c;
  1459.     tmp[1] = 0;
  1460.     return find_last_not_of(tmp, pos);
  1461. }
  1462.  
  1463. template <class charT, class traits, class Allocator >
  1464. inline int
  1465. basic_string<charT, traits, Allocator>::compare (
  1466.   const basic_string<charT, traits, Allocator>& str) const
  1467. {
  1468.     return compare(0,length(),str.c_str(),str.length());
  1469. }
  1470.  
  1471. template <class charT, class traits , class Allocator  >
  1472. inline int
  1473. basic_string<charT, traits, Allocator>::compare (size_type pos,
  1474.                                                  size_type n1,
  1475.                                                  const charT* s) const
  1476. {
  1477.     size_type len = traits::length(s);
  1478.     return compare(pos,n1,s,len);
  1479. }
  1480.  
  1481. template <class charT, class traits , class Allocator  >
  1482. inline int
  1483. basic_string<charT, traits, Allocator>::compare (const charT* s) const
  1484. {
  1485.     size_type len = traits::length(s);
  1486.     return compare(0,length(),s,len);
  1487. }
  1488.  
  1489. //
  1490. // Inlined non-member operators
  1491. //
  1492.  
  1493. template <class charT, class traits , class Allocator  >
  1494. inline basic_string<charT, traits, Allocator> operator+(
  1495.   const basic_string<charT, traits, Allocator>& lhs,
  1496.   const basic_string<charT, traits, Allocator>& rhs)
  1497. {
  1498.     return basic_string<charT, traits, Allocator>(lhs).append(rhs);
  1499. }
  1500.  
  1501. template <class charT, class traits , class Allocator  >
  1502. inline basic_string<charT, traits, Allocator> operator+(
  1503.   const charT*                                  lhs,
  1504.   const basic_string<charT, traits, Allocator>& rhs)
  1505. {
  1506.     return basic_string<charT, traits, Allocator>(lhs).append(rhs);
  1507. }
  1508.  
  1509. template <class charT, class traits , class Allocator  >
  1510. inline basic_string<charT, traits, Allocator> operator+(
  1511.   charT lhs, const basic_string<charT, traits, Allocator>& rhs)
  1512. {
  1513.     return basic_string<charT, traits, Allocator>(1,lhs).append(rhs);
  1514. }
  1515.  
  1516. template <class charT, class traits , class Allocator  >
  1517. inline basic_string<charT, traits, Allocator> operator+(
  1518.   const basic_string<charT, traits, Allocator>& lhs,
  1519.   const charT*                                  rhs)
  1520. {
  1521.     return basic_string<charT,traits,Allocator>(lhs).append(basic_string<charT, traits, Allocator>(rhs));
  1522. }
  1523.  
  1524. template <class charT, class traits , class Allocator  >
  1525. inline basic_string<charT, traits, Allocator> operator+(
  1526.   const basic_string<charT, traits, Allocator>& lhs,
  1527.   charT                                         rhs)
  1528. {
  1529.     return basic_string<charT,traits,Allocator>(lhs).append(basic_string<charT, traits, Allocator>(1,rhs));
  1530. }
  1531.  
  1532. template <class charT, class traits , class Allocator  >
  1533. inline bool operator==(
  1534.   const basic_string<charT, traits, Allocator>& lhs,
  1535.   const basic_string<charT, traits, Allocator>& rhs)
  1536. {
  1537.     return lhs.compare(rhs) == 0 ? true : false ;
  1538. }
  1539.  
  1540. template <class charT, class traits , class Allocator  >
  1541. inline bool operator==(
  1542.   const charT*                                  lhs,
  1543.   const basic_string<charT, traits, Allocator>& rhs)
  1544. {
  1545.    return basic_string<charT,traits,Allocator>(lhs).compare(rhs)==0?true:false;
  1546. }
  1547.  
  1548. template <class charT, class traits , class Allocator  >
  1549. inline bool operator==(
  1550.   const basic_string<charT, traits, Allocator>& lhs,
  1551.   const charT*                                  rhs)
  1552. {
  1553.    return lhs.compare(basic_string<charT,traits,Allocator>(rhs))==0?true:false;
  1554. }
  1555.  
  1556. template <class charT, class traits , class Allocator  >
  1557. inline bool operator<(
  1558.   const basic_string<charT, traits, Allocator>& lhs,
  1559.   const basic_string<charT, traits, Allocator>& rhs)
  1560. {
  1561.     return lhs.compare(rhs) < 0 ? true:false ;
  1562. }
  1563.  
  1564. template <class charT, class traits , class Allocator  >
  1565. inline bool operator<(
  1566.   const charT*                                  lhs,
  1567.   const basic_string<charT, traits, Allocator>& rhs)
  1568. {
  1569.     return basic_string<charT,traits,Allocator>(lhs).compare(rhs)<0?true:false;
  1570. }
  1571.  
  1572. template <class charT, class traits , class Allocator  >
  1573. inline bool operator<(
  1574.   const basic_string<charT, traits, Allocator>& lhs,
  1575.   const charT*                                  rhs)
  1576. {
  1577.   return lhs.compare(basic_string<charT,traits,Allocator>(rhs))<0?true:false;
  1578. }
  1579.  
  1580. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1581. template <class charT, class traits , class Allocator  >
  1582. inline bool operator!=(
  1583.   const basic_string<charT, traits, Allocator>& lhs,
  1584.   const basic_string<charT, traits, Allocator>& rhs)
  1585. {
  1586.     return lhs.compare(rhs) != 0 ? true : false;
  1587. }
  1588. #endif
  1589.  
  1590. template <class charT, class traits , class Allocator  >
  1591. inline bool operator!=(
  1592.   const charT*                                  lhs,
  1593.   const basic_string<charT, traits, Allocator>& rhs)
  1594. {
  1595.    return basic_string<charT,traits,Allocator>(lhs).compare(rhs)!=0?true:false;
  1596. }
  1597.  
  1598. template <class charT, class traits , class Allocator  >
  1599. inline bool operator!=(
  1600.   const basic_string<charT, traits, Allocator>& lhs,
  1601.   const charT*                                  rhs)
  1602. {
  1603.    return lhs.compare(basic_string<charT,traits,Allocator>(rhs))!=0?true:false;
  1604. }
  1605.  
  1606. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1607. template <class charT, class traits , class Allocator  >
  1608. inline bool operator>(
  1609.   const basic_string<charT, traits, Allocator>& lhs,
  1610.   const basic_string<charT, traits, Allocator>& rhs)
  1611. {
  1612.     return lhs.compare(rhs) > 0 ? true : false;
  1613. }
  1614. #endif
  1615.  
  1616. template <class charT, class traits , class Allocator  >
  1617. inline bool operator>(
  1618.   const charT*                                  lhs,
  1619.   const basic_string<charT, traits, Allocator>& rhs)
  1620. {
  1621.    return basic_string<charT,traits,Allocator>(lhs).compare(rhs)>0?true:false;
  1622. }
  1623.  
  1624. template <class charT, class traits , class Allocator  >
  1625. inline bool operator>(
  1626.   const basic_string<charT, traits, Allocator>& lhs,
  1627.   const charT*                                  rhs)
  1628. {
  1629.    return lhs.compare(basic_string<charT,traits,Allocator>(rhs))>0?true:false;
  1630. }
  1631.  
  1632. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1633. template <class charT, class traits , class Allocator  >
  1634. inline bool operator<=(
  1635.   const basic_string<charT, traits, Allocator>& lhs,
  1636.   const basic_string<charT, traits, Allocator>& rhs)
  1637. {
  1638.     return lhs.compare(rhs) <= 0 ? true : false;
  1639. }
  1640. #endif
  1641.  
  1642. template <class charT, class traits , class Allocator  >
  1643. inline bool operator<=(
  1644.   const charT*                                  lhs,
  1645.   const basic_string<charT, traits, Allocator>& rhs)
  1646. {
  1647.   return basic_string<charT,traits,Allocator>(lhs).compare(rhs)<=0?true:false;
  1648. }
  1649.  
  1650. template <class charT, class traits , class Allocator  >
  1651. inline bool operator<=(
  1652.   const basic_string<charT, traits, Allocator>& lhs,
  1653.   const charT*                                  rhs)
  1654. {
  1655.   return lhs.compare(basic_string<charT,traits,Allocator>(rhs))<=0?true:false;
  1656. }
  1657.  
  1658. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1659. template <class charT, class traits , class Allocator  >
  1660. inline bool operator>=(
  1661.   const basic_string<charT, traits, Allocator>& lhs,
  1662.   const basic_string<charT, traits, Allocator>& rhs)
  1663. {
  1664.     return lhs.compare(rhs) >= 0 ? true:false;
  1665. }
  1666. #endif
  1667.  
  1668. template <class charT, class traits , class Allocator  >
  1669. inline bool operator>=(
  1670.   const charT*                                  lhs,
  1671.   const basic_string<charT, traits, Allocator>& rhs)
  1672. {
  1673.    return basic_string<charT,traits,Allocator>(lhs).compare(rhs)>=0?true:false;
  1674. }
  1675.  
  1676. template <class charT, class traits , class Allocator  >
  1677. inline bool operator>=(
  1678.   const basic_string<charT, traits, Allocator>& lhs,
  1679.   const charT*                                  rhs)
  1680. {
  1681.    return lhs.compare(basic_string<charT,traits,Allocator>(rhs))>=0?true:false;
  1682. }
  1683.  
  1684. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1685. template <class charT, class traits, class Allocator>
  1686. inline void swap(basic_string<charT,traits,Allocator>& a, 
  1687.           basic_string<charT,traits,Allocator>& b)
  1688. {
  1689.     a.swap(b);
  1690. }
  1691. #endif
  1692.  
  1693. #ifndef _RW_STD_IOSTREAM
  1694.  
  1695. template<class charT, class traits , class Allocator >
  1696. istream & _RWSTDExportTemplate operator >> (
  1697.   istream & is, basic_string<charT, traits, Allocator > & str);
  1698.  
  1699. template<class charT, class traits , class Allocator >
  1700. ostream& _RWSTDExportTemplate operator << (
  1701.   ostream & os, const basic_string<charT, traits, Allocator > & str);
  1702.  
  1703. template<class Stream, class charT, class traits , class Allocator >
  1704. Stream& _RWSTDExportTemplate getline(Stream& is, 
  1705.           basic_string<charT, traits,Allocator>& str, charT delim);
  1706.  
  1707. template<class Stream, class charT, class traits , class Allocator >
  1708. Stream& _RWSTDExportTemplate getline(Stream& is, 
  1709.           basic_string<charT, traits,Allocator>& str)
  1710. { return getline(is,str,'\n'); }
  1711.  
  1712. #endif /*_RW_STD_IOSTREAM*/
  1713.  
  1714. #ifdef _RWSTD_MSC22_STATIC_INIT_BUG
  1715. #undef npos
  1716. #endif
  1717.  
  1718. #ifndef _RWSTD_NO_NAMESPACE
  1719. }
  1720. #endif
  1721.  
  1722. #ifdef _RWSTD_COMPILE_INSTANTIATE
  1723. #include <string.cc>
  1724. #endif
  1725.  
  1726. #pragma option pop
  1727. #endif /*defined __STD_STRING*/
  1728.